﻿#ifndef SUPERSERIALPORT_H
#define SUPERSERIALPORT_H

#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QVector>
#include <QByteArray>
class SuperSerialPort :public QObject
{
    Q_OBJECT
public:
    SuperSerialPort();
signals:
    void    ReseiveDatas(QByteArray value);//将读取的数据发送出去
public:
    bool    FoundPort();//寻找串口
    bool    OpenPort(QString name,int BaudRate, int DataBits, int Parity, int StopBits);//打开串口
    void    ClosePort();
    void    ReadDates(); //读取数据
    void    WriteDates(QByteArray buf);//写入数据
    void    GetCheckCode(QVector<char> startCode,QVector<char> endCode);
private:
    QSerialPort *m_serial;
    QVector<char> m_startCode;
    QVector<char> m_endCode;
private:
     /// <summary>
     /// 生成CRC校验位
     /// </summary>
     /// <param name="ptr"></param>
     /// <param name="len"></param>
     /// <param name="crc"></param>
    void CommonCrc8(unsigned char ptr[], int len, unsigned char *crc);
    void GenerateCrc8(unsigned char c, unsigned char *crc);
    unsigned char CRC8(QByteArray buffer, int startlength, int length);

};
#endif // SUPERSERIALPORT_H
